//
//  WmcWatermarkAPI.swift
//  YPWatermarkCamera
//
//  Created by 周诗松 on 2022/3/29.
//

import YPBedrock
import YPNetwork

struct WmcWatermarkAPI {

    /// 获取水印列表
    /// - DocumentUrl: http://rap2.taobao.org/organization/repository/editor?id=297881&mod=503154
    /// - Returns: list
    static func fetchWatermarkList(success: YPBlock.OneParam<[WmcWatermarkClassifyModel]>? = nil,
                                   failure: YPNetworkRequestFailure? = nil)
    {
        WmcNetworkRequest.requestData(path: "/api/wm/get", configuration: { request in
            request.method = .get
        }, success: { (response: YPNetworkResponse) in
            if let dic = response.data as? [String: Any],
               let list = dic["list"] as? [Any]
            {
                let resu = list.parseListModelWithClass(WmcWatermarkClassifyModel.self)
                success?(resu)
            }
        }, failure: failure)
    }
    
    
    /// 获取用户使用过模板列表接口
    /// - DocumentUrl: http://rap2.taobao.org/organization/repository/editor?id=297881&mod=503154&itf=2236953
    /// - Returns: Observable<WmcUsedWatermarkModel>
    static func fetchUsedWatermarkList(projectId: String) -> Observable<[WmcUsedWatermarkModel]> {
        let path = "/api/wm/template-used?corp_id=\(projectId)"
        return WmcNetworkRequest.requestData(path: path) { request in
            request.method = .get
        }.parseListModelWithClass(WmcUsedWatermarkModel.self)
    }
}
